package com.xinxing.learning.datasource.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * 定义两个数据源
 */
@Configuration
@PropertySource("classpath:config/jdbc.properties")
public class DataSourceConfig {

    @Bean("first")
    @ConfigurationProperties(prefix = "spring.datasource.first")
    public DataSource masterDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean("second")
    @ConfigurationProperties(prefix = "spring.datasource.second")
    public DataSource slaveDataSource() {
        return DataSourceBuilder.create().build();
    }
}
